import mixin from '../mixin';
import { HttpNotice, HttpReadNotice } from '../../../service/notice';
import { mapMutations } from 'vuex';

export default {
    mixins: [mixin],
    data() {
        return {
            loading: false,
            formData: {},
        }
    },
    created() {
        this.getDetail();
    },
    methods: {
        ...mapMutations(['storeEmit']),
        //获取模板数据
        getDetail() {
            this.loading = true;
            HttpNotice({ id: this.id }).then(res => {
                const data = res.data || {};
                this.formData = data.message;
                if (this.formData.format === 1) {
                    this.formData.content = this.formData.content.replace(/(\n|'\\n')/g, '<br/>')
                }
                this.loading = false;
                const entity = data.entity || {};
                const readStatus = entity.notifyReadStatus;
                if (!readStatus) {
                    HttpReadNotice({ id: entity.id }).then(res => {
                        // const data = res.data || {};
                        this.loading = false;
                        this.storeEmit({ name: 'pullNoticeStats' });
                    }).catch(err => {
                        this.loading = false;
                        this.$Message.error(err.message);
                    });
                }
            }).catch(err => {
                this.loading = false;
                this.$Message.error(err.message);
            })
        },
        close() {
            this.$emit('on-close');
        }
    },
    computed: {
        getBase() {
            return [
                {
                    label: "类型",
                    key: "bizeventTypeId",
                    options: this.getNoticeEevntTypes
                },
                {
                    label: "标题",
                    key: "title",
                },
                {
                    label: "时间",
                    key: "createdAt",
                },
                {
                    label: "简述",
                    key: "brief",
                },
                {
                    label: "链接",
                    key: "url",
                    show: !!this.formData.url
                },
                {
                    label: "关联平台单据编号",
                    key: "idLabel",
                    show: !!this.formData.idLabel
                },
                {
                    label: "关联来源单据编号",
                    key: "srcLabel",
                    show: !!this.formData.srcLabel
                },
                {
                    label: "内容",
                    tag: "pre",
                    key: "content",
                },

            ]
        }
    }
}
